package com.example.tourstor.myself;

import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;

import com.example.tourstor.BaseBean;
import com.example.tourstor.DividerItemDecoration;
import com.example.tourstor.R;

import java.util.ArrayList;
import java.util.List;

public class CardActivity extends AppCompatActivity {

    Toolbar card_toolbar;
    RecyclerView mCardRecyclerview;

    private CardAdapter mCradAdapter = null;
    private LinearLayoutManager mLinearLayoutManager;
    private List<BaseBean> mBaseBeans = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_card);

        mCardRecyclerview = (RecyclerView) findViewById(R.id.card_recycle);
        setToolBar();
        initData();
    }

    private void setToolBar() {
        card_toolbar = (Toolbar) findViewById(R.id.card_toolbar);

        card_toolbar.setTitle("银行卡");
        card_toolbar.setTitleTextColor(Color.WHITE);

        this.setSupportActionBar(card_toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);//左侧添加一个默认的返回图标
        getSupportActionBar().setHomeButtonEnabled(true);//设置返回键可用
        this.getSupportActionBar().setDisplayShowTitleEnabled(true);
    }

    //Toolbar的事件---返回
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if(item.getItemId() == android.R.id.home){
            finish();
        }
        return super.onOptionsItemSelected(item);
    }

    private void initData() {
        mCradAdapter = new CardAdapter(this);
        mLinearLayoutManager = new LinearLayoutManager(this);
        mCardRecyclerview.setLayoutManager(mLinearLayoutManager);
        DividerItemDecoration itemDecorationHeader = new DividerItemDecoration(this, DividerItemDecoration.VERTICAL_LIST);
        itemDecorationHeader.setDividerDrawable(ContextCompat.getDrawable(this, R.drawable.divider_main_bg_height_1));
        mCardRecyclerview.addItemDecoration(itemDecorationHeader);
        mCardRecyclerview.setAdapter(mCradAdapter);
        for (int i = 0; i < 30; i++) {
            BaseBean mybean = new BaseBean();

            mybean.setCardNum("**** *****20" + i);

            mBaseBeans.add(mybean);
            mCradAdapter.notifyAdapter(mBaseBeans, false);
        }
    }

}
